package com.sam.designpatterns;

/**
 * builder模式
 * Created by samwang on 2018/4/21.
 */
public class BuilderDemo {
    private String str;
    private int i;
    private long l;

    public static void main(String[] args) {
        BuilderDemo.Builder builder = new BuilderDemo.Builder();
        BuilderDemo demo = builder.setInt(1)
                .setStr("NB")
                .setLong(System.currentTimeMillis())
                .create();
    }

    static class Builder {
        BuilderDemo demo;

        public Builder() {
            demo = new BuilderDemo();
        }

        public Builder setStr(String str) {
            demo.str = str;
            return this;
        }

        public Builder setInt(int i) {
            demo.i = i;
            return this;
        }

        public Builder setLong(long l) {
            demo.l = l;
            return this;
        }

        public BuilderDemo create() {
            return demo;
        }
    }

}
